//
//  KRedEnvelopeTableViewCell.m
//  DrugPin
//
//  Created by guohe on 2018/9/10.
//  Copyright © 2018年 outang. All rights reserved.
//

#import "KRedEnvelopeTableViewCell.h"

@implementation KRedEnvelopeTableViewCell

- (instancetype)initWithTableView:(UITableView*)tableView WithShowtype:(KHomePageTableViewCellType)showtype reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
        switch (self.tableCellType) {
            case KHomePageTableViewCellType_RedEnvelope:{   //红包
                [self setupUI];
                self.redEnvelopeIcon.hidden = NO;
                self.redEnvelopeLabel.hidden = NO;
                [self setDataWithRedEnvelopeModel:self.redEnveDataListModel];
            }
                break;
            case KHomePageTableViewCellType_Cultivate:{   //培训
                [self setupUI];
                self.redEnvelopeIcon.hidden = YES;
                self.redEnvelopeLabel.hidden = YES;
                [self setDataWithCultivateModel:self.trainActDataListModel];
            }
                
            default:
                break;
        }
    }
    return self;
}

-(void)setupUI{
    [self addSubview:self.statusBtn];
    [self addSubview:self.redEnveTypeBtn];
    [self addSubview:self.redEnvelopeIcon];
    [self addSubview:self.redEnvelopeLabel];
    [self addSubview:self.contentImageView];
    [self addSubview:self.mainTitleLabel];
    [self addSubview:self.subTitleLabel];
    
    [self.statusBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(self).mas_offset(15);
        make.width.mas_equalTo(66);
        make.height.mas_equalTo(22);
    }];

    [self.redEnveTypeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).mas_offset(15);
        make.left.equalTo(self.statusBtn.mas_right).mas_offset(10);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(21.5);
    }];
    
    [self.redEnvelopeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).mas_offset(15);
        make.right.equalTo(self).mas_offset(-15);
        make.width.mas_equalTo(60);
    }];
    
    [self.redEnvelopeIcon mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self).mas_offset(15);
        make.right.equalTo(self.redEnvelopeLabel.mas_left).mas_offset(-4);
        make.centerY.equalTo(self.redEnvelopeLabel);
        make.width.mas_equalTo(12);
        make.height.mas_equalTo(15);
    }];
    
    [self.contentImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.statusBtn.mas_bottom).mas_offset(10);
        make.left.equalTo(self).mas_offset(15);
        make.right.equalTo(self).mas_offset(-15);
        make.height.mas_equalTo(143);
    }];
    
    [self.mainTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentImageView.mas_bottom).mas_offset(10);
        make.left.equalTo(self).mas_offset(15);
        make.right.equalTo(self).mas_offset(-15);
    }];
    
    [self.subTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mainTitleLabel.mas_bottom).mas_offset(10);
        make.left.equalTo(self).mas_offset(15);
        make.right.equalTo(self).mas_offset(-15);
    }];
    
}

-(void)setTableCellType:(KHomePageTableViewCellType)tableCellType{
    switch (tableCellType) {
        case KHomePageTableViewCellType_RedEnvelope:{   //红包
            [self setupUI];
            [self setDataWithRedEnvelopeModel:self.redEnveDataListModel];
        }
            break;
        case KHomePageTableViewCellType_Cultivate:{   //培训
            [self setupUI];
            self.redEnvelopeIcon.hidden = YES;
            self.redEnvelopeLabel.hidden = YES;
            [self setDataWithCultivateModel:self.trainActDataListModel];
        }

        default:
            break;
    }
}

-(void)setDataWithRedEnvelopeModel:(KRedEnvelopeDataListModel *)model{
    
    [self.statusBtn setTitle:model.statusName forState:UIControlStateNormal];
    
    self.redEnvelopeIcon.image = [UIImage imageNamed:@"icon_hongbao"];

    NSString *priseStr = [NSString stringWithFormat:@"¥ %@ ~ %@",model.MinMoney,model.MaxMoney];
    self.redEnvelopeLabel.text = priseStr; //富文本处理待加入
    
    [self.contentImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.Pic]] placeholderImage:[UIImage imageNamed:@"loading"]];
    
    self.mainTitleLabel.text = model.Theme;
    
    NSString *contentStr = [NSString stringWithFormat:@"红包开抢:%@-%@      总盒数:%@,剩余盒数:%@",model.StartDate,model.EndDate,model.TotalCount,model.LeaveCount];
    self.subTitleLabel.text = contentStr;
}

-(void)setDataWithCultivateModel:(KTrainingActivitiesDataListModel *)model{
    
    [self.statusBtn setTitle:model.StatusName forState:UIControlStateNormal];
    
    [self.contentImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.Pic]] placeholderImage:[UIImage imageNamed:@"loading"]];
    
    self.mainTitleLabel.text = model.Theme;
    
    NSString *contentStr = [NSString stringWithFormat:@"活动时间:%@-%@",model.StartDate,model.EndDate];
    self.subTitleLabel.text = contentStr;
}

#pragma mark - getter

-(UIButton *)statusBtn
{
    if (!_statusBtn) {
        _statusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _statusBtn.userInteractionEnabled = NO;//不可点击效果，当标签用，主要用于显示
        _statusBtn.layer.masksToBounds = YES;
        _statusBtn.layer.cornerRadius = 11;
        [_statusBtn setTitle:self.redEnveDataListModel.statusName forState:UIControlStateNormal];
        _statusBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_statusBtn setTitleColor:KColorOneAlpha(48,138,245) forState:UIControlStateNormal];
        [_statusBtn setBackgroundColor:KColorOneAlpha(195,222,253)];
    }
    return _statusBtn;
}

-(UIButton *)redEnveTypeBtn{
    if (!_redEnveTypeBtn) {
        _redEnveTypeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _redEnveTypeBtn.userInteractionEnabled = NO;//不可点击效果，当标签用，主要用于显示
        _redEnveTypeBtn.layer.masksToBounds = YES;
        _redEnveTypeBtn.layer.cornerRadius = 11;
        [_redEnveTypeBtn setTitle:@"竞赛红包" forState:UIControlStateNormal]; //待加入，数组格式
        [_redEnveTypeBtn setTitleColor:KColorOneAlpha(48,138,245) forState:UIControlStateNormal];
        [_redEnveTypeBtn setBackgroundColor:KWhiteColor];
        _redEnveTypeBtn.layer.borderWidth = 1;
        _redEnveTypeBtn.layer.borderColor = KColor(48,138,245, 1).CGColor;
    }
    return _redEnveTypeBtn;
}

-(UIImageView *)redEnvelopeIcon{
    if (!_redEnvelopeIcon) {
        _redEnvelopeIcon = [[UIImageView alloc] init];
        _redEnvelopeIcon.image = [UIImage imageNamed:@"icon_hongbao"];
    }
    return _redEnvelopeIcon;
}

-(UILabel *)redEnvelopeLabel{
    if (!_redEnvelopeLabel) {
        _redEnvelopeLabel = [[UILabel alloc] init];
//        NSString *priseStr = [NSString stringWithFormat:@"¥ %@ ~ %@",self.MinMoney,self.MaxMoney];
//        _redEnvelopeLabel.text = priseStr; //富文本处理待加入
        _redEnvelopeLabel.font = [UIFont systemFontOfSize:17];
        _redEnvelopeLabel.textColor = KColorOneAlpha(255,68,68);
    }
    return _redEnvelopeLabel;
}

-(UIImageView *)contentImageView{
    if (!_contentImageView) {
        _contentImageView = [[UIImageView alloc] init];
//        [_contentImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.Pic]] placeholderImage:[UIImage imageNamed:@"loading"]];
        _redEnveTypeBtn.layer.masksToBounds = YES;
        _redEnveTypeBtn.layer.cornerRadius = 4;
    }
    return _contentImageView;
}


-(UILabel *)mainTitleLabel{
    if (!_mainTitleLabel) {
        _mainTitleLabel = [[UILabel alloc] init];
//        _mainTitleLabel.text = self.Theme;
        _mainTitleLabel.numberOfLines = 0;
        _mainTitleLabel.font = [UIFont systemFontOfSize:14];
        _mainTitleLabel.textColor = KColorOneAlpha(51,51,51);
    }
    return _mainTitleLabel;
}

-(UILabel *)subTitleLabel{
    if (!_subTitleLabel) {
        _subTitleLabel = [[UILabel alloc] init];
//        NSString *contentStr = [NSString stringWithFormat:@"红包开抢:%@-%@      总盒数:%@,剩余盒数:%@",self.StartDate,self.EndDate,self.TotalCount,self.LeaveCount];
//        _subTitleLabel.text = contentStr;
        _subTitleLabel.numberOfLines = 0;
        _subTitleLabel.font = [UIFont systemFontOfSize:12];
        _subTitleLabel.textColor = KColorOneAlpha(153,153,153);
    }
    return _subTitleLabel;
}

-(KRedEnvelopeDataListModel *)redEnveDataListModel{
    if (!_redEnveDataListModel) {
        _redEnveDataListModel = [[KRedEnvelopeDataListModel alloc] init];
    }
    return _redEnveDataListModel;
}

-(KTrainingActivitiesDataListModel *)trainActDataListModel{
    if (!_trainActDataListModel) {
        _trainActDataListModel = [[KTrainingActivitiesDataListModel alloc] init];
    }
    return _trainActDataListModel;
}


@end
